class Solution:
    def makeFancyString(self, s: str) -> str:
        now = ""
        num = 0
        res = []
        for ch in s:
            if ch != now:
                res.append(now * num)
                now, num = ch, 1
            else:
                num = min(num + 1, 2)
        res.append(now * num)
        return "".join(res)


if __name__ == "__main__":
    print(Solution().makeFancyString("leeetcode"))  # leetcode
    print(Solution().makeFancyString("aaabaaaa"))  # aabaa
    print(Solution().makeFancyString("aab"))  # aab
